class Foo {
private:
    mutex m_mtx1;
    mutex m_mtx2;
    mutex m_mtx3;
public:
    Foo() {
        
        m_mtx2.lock();
        m_mtx3.lock();
    }

    void first(function<void()> printFirst) {
        
        m_mtx1.lock();
        printFirst();
        m_mtx2.unlock();
    }

    void second(function<void()> printSecond) {
        
        m_mtx2.lock();
        printSecond();
        m_mtx3.unlock();
    }

    void third(function<void()> printThird) {
        
        m_mtx3.lock();
        printThird();
        m_mtx1.unlock();
    }
};
